/**
 * 功能:头脑之神答题

 */

var setupTask;

//设置多久开启一次(小时:为单位)
var starttime = 1;

//设置每次活动结束的时间(分钟:为单位)
var overtime = 10;

//设置每次副本开启的分钟段(分钟:为单位)
var startminute = 18;

function init() {
	scheduleNew();
}

function scheduleNew() {
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时 24小时制
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	cal.set(java.util.Calendar.HOUR, 0); //设定的小时 12小时制
	cal.set(java.util.Calendar.MINUTE, startminute); //设定的分钟
	cal.set(java.util.Calendar.SECOND, 0); //设定的秒钟
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 * 60 * 60 * starttime; //设置多久开启
	}
	setupTask = em.scheduleAtTimestamp("startEvent", nextTime);
}

function startEvent() {
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时  24小时制
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	cal.set(java.util.Calendar.HOUR, 0); //设定的小时 12小时制
	cal.set(java.util.Calendar.MINUTE, startminute); //设定的分钟
	cal.set(java.util.Calendar.SECOND, 0); //设定的秒钟
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 * 60 * overtime; //设置多久结束
	}
	setupTask = em.scheduleAtTimestamp("finishEvent", nextTime);
	em.broadcastServerMsg(5121076, "您的脑袋够聪明么？快来挑战PPMS专属副本头脑之神赢取海量豪礼！", true);//闪电的气象效果漂浮特效
	em.broadcastServerMsg("您的脑袋够聪明么？快来挑战PPMS专属副本头脑之神赢取海量豪礼！");
}

function finishEvent() {
	em.broadcastServerMsg("[头脑之神]：答题入口已关闭请等待下个小时18分钟再进入！每人每天只能参加一次！");
	scheduleNew();
}

function cancelSchedule() {
	if (setupTask != null) {
		setupTask.cancel(true);
	}

}
